<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('技术功能列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa fa-sitemap"></i> 项目结构树
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool" href="javascript:void(0)" onclick="program()" title="管理项目"><i class="fa fa-edit"></i></a>
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="ibox-title ibox-title-gray dashboard-header">
            <h5>资料详情</h5>
        </div>
        <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#jishu_info" data-toggle="tab" aria-expanded="true">技术功能</a></li>
                <li><a href="#jiaofu_info" data-toggle="tab" aria-expanded="false">交付清单</a></li>
            </ul>
            <div class="tab-content">
                <!--技术功能-->
                <div class="tab-pane active" id="jishu_info">
                    <div class="container-div">
                        <div class="row">
                            <div class="col-sm-12 search-collapse">
                                <form id="formId1">
                                    <div class="select-list">
                                        <ul>
                                            <input type="hidden" name="relateId" id="relateId"/>
                                            <li>
                                                <label>名称：</label>
                                                <input type="text" name="name"/>
                                            </li>
                                            <li>
                                                <label>状态：</label>
                                                <select name="status" th:with="type=${@dict.getType('cd_item_status')}">
                                                    <option value="">所有</option>
                                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                                </select>
                                            </li>
                                            <li class="select-time">
                                                <label>计划时间：</label>
                                                <input type="text" class="time-input" placeholder="开始时间" name="planStartDate"/>
                                                <span>-</span>
                                                <input type="text" class="time-input" placeholder="结束时间" name="planEndDate"/>
                                            </li>
                                            <li class="select-time">
                                                <label>实际时间：</label>
                                                <input type="text" class="time-input" placeholder="开始时间" name="actStartDate"/>
                                                <span>-</span>
                                                <input type="text" class="time-input" placeholder="结束时间" name="actEndDate"/>
                                            </li>
                                            <li>
                                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('formId1','bootstrap-table1')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('formId1','bootstrap-table1')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                            </li>
                                        </ul>
                                    </div>
                                </form>
                            </div>

                            <div class="btn-group-sm" id="toolbar1" role="group">
                                <a class="btn btn-success" onclick="addItem()" shiro:hasPermission="cd:programItem:add">
                                    <i class="fa fa-plus"></i> 添加
                                </a>
                                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="cd:programItem:edit">
                                    <i class="fa fa-edit"></i> 修改
                                </a>
                                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="cd:programItem:remove">
                                    <i class="fa fa-remove"></i> 删除
                                </a>
                                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cd:programItem:export">
                                    <i class="fa fa-download"></i> 导出
                                </a>
                                <a class="btn btn-info single disabled" onclick="uploadDoc()">
                                    <i class="fa fa-upload"></i> 上传
                                </a>
                            </div>
                            <div class="col-sm-12 select-table table-striped">
                                <table id="bootstrap-table1"></table>
                            </div>
                        </div>
                    </div>
                </div>

                <!--交付清单-->
                <div class="tab-pane" id="jiaofu_info">
                    <div class="container-div">
                        <div class="row">
                            <div class="col-sm-12 search-collapse">
                                <form id="formId2">
                                    <div class="select-list">
                                        <ul>
                                            <input type="hidden" name="relateId" id="relateId2"/>
                                            <li>
                                                <label>交付单：</label>
                                                <input type="text" name="noteName"/>
                                            </li>
                                            <li>
                                                <label>状态：</label>
                                                <select name="status" th:with="type=${@dict.getType('cd_item_status')}">
                                                    <option value="">所有</option>
                                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                                </select>
                                            </li>
                                            <li class="select-time">
                                                <label>计划时间：</label>
                                                <input type="text" class="time-input" placeholder="开始时间" name="planStartDate"/>
                                                <span>-</span>
                                                <input type="text" class="time-input" placeholder="结束时间" name="planEndDate"/>
                                            </li>
                                            <li class="select-time">
                                                <label>实际时间：</label>
                                                <input type="text" class="time-input" placeholder="开始时间" name="actStartDate"/>
                                                <span>-</span>
                                                <input type="text" class="time-input" placeholder="结束时间" name="actEndDate"/>
                                            </li>
                                            <li>
                                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('formId2','bootstrap-table2')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('formId2','bootstrap-table2')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                            </li>
                                        </ul>
                                    </div>
                                </form>
                            </div>

                            <div class="btn-group-sm" id="toolbar2" role="group">
                                <a class="btn btn-success" onclick="addItem2()" shiro:hasPermission="cd:programPayNote:add">
                                    <i class="fa fa-plus"></i> 添加
                                </a>
                                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="cd:programPayNote:edit">
                                    <i class="fa fa-edit"></i> 修改
                                </a>
                                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="cd:programPayNote:remove">
                                    <i class="fa fa-remove"></i> 删除
                                </a>
                                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cd:programPayNote:export">
                                    <i class="fa fa-download"></i> 导出
                                </a>
                            </div>
                            <div class="col-sm-12 select-table table-striped">
                                <table id="bootstrap-table2"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('cd:programItem:edit')}]];
        var removeFlag = [[${@permission.hasPermi('cd:programItem:remove')}]];
        var editFlag2 = [[${@permission.hasPermi('cd:programPayNote:edit')}]];
        var removeFlag2 = [[${@permission.hasPermi('cd:programPayNote:remove')}]];
        var statusDatas = [[${@dict.getType('cd_item_status')}]];
        var prefix = ctx + "cd/programItem";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185, resizeWithWindow: false });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryItemTree();
            queryList();
            queryListPayNote();
        });
        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryItemTree();
        });

        function addItem(){
            var relateId = $('#relateId').val();
            if(relateId == null || relateId == ''){
                $.modal.alertWarning("请选择一条项目");
            }else {
                $.modal.open("添加目录", prefix + "/add/"+relateId);
            }
        }

        function uploadDoc(id){
            if ($.common.isEmpty(id)) {
                var id = $.table.selectColumns("id");
                if ($.common.isEmpty(id)) {
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }
            }
            console.log(id)
            var url = prefix + "/upload?relateId="+id+"&relateMode=2";
            $.modal.open("技术功能上传", url);
        }

        function queryItemTree()
        {
            var url = ctx + "cd/document/itemTreeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $('#relateId').val(treeNode.id);
                $('#relateId2').val(treeNode.id);
                // $('#relateName').val(treeNode.name);
                $.table.search('formId2','bootstrap-table2');
                $.table.search('formId1','bootstrap-table1')
            }
        }
        function queryList(){
            var options = {
                id: "bootstrap-table1",
                formId: "formId1",
                toolbar: "toolbar1",
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "技术功能",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: '序号',
                        visible: false
                    },
                    {
                        field: 'relateId',
                        title: '项目ID',
                        visible: false
                    },
                    {
                        field: 'program.name',
                        title: '项目名称'
                    },
                    {
                        field: 'name',
                        title: '名称'
                    },
                    {
                        field: 'status',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(statusDatas, value);
                        }
                    },
                    {
                        field: 'planStartDate',
                        title: '计划开始时间'
                    },
                    {
                        field: 'planEndDate',
                        title: '计划结束时间'
                    },
                    {
                        field: 'actStartDate',
                        title: '实际开始时间'
                    },
                    {
                        field: 'actEndDate',
                        title: '实际结束时间'
                    },
                    {
                        field: 'nowRiskPoint',
                        title: '当前分险点描述'
                    },
                    {
                        field: 'nowProgress',
                        title: '当前进度描述'
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    },
                    {
                        title: '附件',
                        formatter: function(value, row, index) {
                            var actions = [];
                            //1项目集；2技术功能；3.交付清单
                            actions.push('<a type="button" class="btn btn-box-tool" onclick="relate('+row.id+',\'2\')" title="管理附件"><i class="fa fa-edit"></i></a>');
                            return actions.join('');
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="uploadDoc(\'' + row.id + '\')"><i class="fa fa-upload"></i>上传</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }

        /* 管理-项目 */
        function program() {
            var url = ctx + "cd/program";
            $.modal.openTab("项目管理", url);
        }
        /* 管理-附件 */
        function relate(relate_id,relate_mode) {
            var url = ctx + "cd/programFile/ck/"+relate_id+"/"+relate_mode;
            $.modal.openTab("附件管理", url);
        }

        function queryListPayNote(){
            var prefix = ctx + "cd/programPayNote";
            var options = {
                id: "bootstrap-table2",
                formId: "formId2",
                toolbar: "toolbar2",
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "交付清单",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: '序号',
                        visible: false
                    },
                    {
                        field: 'relateId',
                        title: '项目ID',
                        visible: false
                    },
                    {
                        field: 'program.name',
                        title: '项目名称'
                    },
                    {
                        field: 'noteName',
                        title: '交付单'
                    },
                    {
                        field: 'desc',
                        title: '描述'
                    },
                    {
                        field: 'status',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(statusDatas, value);
                        }
                    },
                    {
                        field: 'planStartDate',
                        title: '计划开始时间'
                    },
                    {
                        field: 'planEndDate',
                        title: '计划结束时间'
                    },
                    {
                        field: 'actStartDate',
                        title: '实际开始时间'
                    },
                    {
                        field: 'actEndDate',
                        title: '实际结束时间'
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag2 + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag2 + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }

        //新增交付单
        function addItem2(){
            var prefix = ctx + "cd/programPayNote";
            var relateId2 = $('#relateId2').val();
            if(relateId2 == null || relateId2 == ''){
                $.modal.alertWarning("请选择一条项目");
            }else {
                $.modal.open("添加目录", prefix + "/add/"+relateId2);
            }
        }
    </script>
    <style>
        .ui-layout-west {
            width: 254px !important;
        }
        .ui-layout-resizer-west-open{
            left: 254px !important;
        }
        .ui-layout-resizer-west-close{
            left: 0px !important;
        }
    </style>
</body>
</html>
